package com.hk.core.data.r2dbc.repository;

import org.springframework.data.domain.Persistable;
import org.springframework.data.r2dbc.core.R2dbcEntityOperations;
import org.springframework.data.r2dbc.core.ReactiveDataAccessStrategy;
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactoryBean;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.r2dbc.core.DatabaseClient;

import java.io.Serializable;

/**
 * @author Kevin
 */
public class TenantR2dbcRepositoryFactoryBean<T extends BaseR2dbcRepository<S, ID>, S extends Persistable<ID>,
        ID extends Serializable>
        extends R2dbcRepositoryFactoryBean<T, S, ID> {

    public TenantR2dbcRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
        super(repositoryInterface);
    }

    @Override
    protected RepositoryFactorySupport getFactoryInstance(DatabaseClient client,
                                                          ReactiveDataAccessStrategy dataAccessStrategy) {
        return new TenantR2dbcRepositoryFactory(client, dataAccessStrategy);
    }

    @Override
    protected RepositoryFactorySupport getFactoryInstance(R2dbcEntityOperations operations) {
        return new TenantR2dbcRepositoryFactory(operations);
    }

}
